package com.example.academicsystem.server.controller.admin;

import com.example.academicsystem.pojo.dto.TeacherDto;
import com.example.academicsystem.pojo.dto.TeacherInsertDto;
import com.example.academicsystem.pojo.dto.TeacherUpdateDto;
import com.example.academicsystem.result.PageResult;
import com.example.academicsystem.result.Result;
import com.example.academicsystem.server.service.AdminService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@RestController
@RequestMapping("/admin/teacher")
public class AdminTeacherController {
    @Autowired
    private AdminService adminService;


    /**
     * 分页查询教师端（所有，根据teacher_id，根据教师名字）
     * */
    @PostMapping("/page")
    public Result<PageResult> teacherPageQuery(@RequestBody TeacherDto teacherDto){
        log.info("teacherPageQuery");
        PageResult pageResult = adminService.teacherPageQuery(teacherDto);
        return Result.success(pageResult);
    }
    /**
     * 新增教师
     * */
    @PostMapping("/insert")
    public Result teacherInsert(@RequestBody TeacherInsertDto teacherInsertDto){
        log.info("teacherInsert");
        adminService.teacherInsert(teacherInsertDto);
        return Result.success();
    }

    /**
     * 删除教师 by id（同时删除 course—teacher）
     * */
    @DeleteMapping("/delete")
    public Result teacherDeleteById(@RequestParam("id") String teacherId){
        log.info("teacherDeleteById:"+teacherId);
        adminService.teacherDeleteById(teacherId);
        return Result.success();
    }
    /**
     * 删除course—teacher by teacherId
    * */
    @DeleteMapping("/delete/course")
    public Result courseTeacherDeleteById(@RequestParam("id") String teacherId){
        log.info("courseTeacherDeleteById:"+teacherId);
        adminService.courseTeacherDeleteById(teacherId);
        return Result.success();
    }
    /**
     * 修改教师 by id
     * */
    @PutMapping("/update")
    public Result teacherUpdateById(@RequestBody TeacherUpdateDto teacherUpdateDto){
        log.info("teacherUpdateById:"+teacherUpdateDto.getTeacherId());
        adminService.teacherUpdateById(teacherUpdateDto);
        return Result.success();
    }
}
